package com.ruoyi.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.common.SysConstant;
import com.ruoyi.system.domain.GgPzRedis;
import com.ruoyi.system.service.IGgPzRedisService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import start.spring.basic.log.ServiceLog;
import start.spring.basic.page.PageQuery;
import start.spring.basic.page.PageResult;
import start.spring.basic.response.ResponseData;
import start.spring.basic.response.ResponsePage;

/**
 * 
 * @author xuyy
 * @date 2023-08-07
 *
 */
@RestController
@RequestMapping("/redisconfig")
@Api(tags = "redis配置相关接口")
public class GgPzRedisController extends BaseController {
	
    @Autowired
    private IGgPzRedisService ggPzRedisService;
	
    @ServiceLog(businessType = "查询redis配置列表", systemType = SysConstant.SYSTEM_TYPE, recordResult = false, userId = "")
    @RequiresPermissions("system:redisconfig:list")
    @PostMapping("/list")
    @ApiOperation(value = "查询redis配置列表", notes = "分页查询")
    public ResponsePage<GgPzRedis> list(PageQuery pageQuery, @RequestBody GgPzRedis ggPzRedis) {
    	return super.returnResponse(this.ggPzRedisService.selectGgPzRedisPageList(pageQuery, ggPzRedis));
    }
    
    @ServiceLog(businessType = "查询redis配置详情", systemType = SysConstant.SYSTEM_TYPE, recordResult = true, userId = "")
    @RequiresPermissions("system:redisconfig:list")
    @PostMapping("/detail")
    @ApiOperation(value = "查询redis配置详情", notes = "单条记录详情查询")
    public ResponseData<GgPzRedis> detail(@RequestBody GgPzRedis ggPzRedis) {
    	PageResult<GgPzRedis> pageResult = this.ggPzRedisService.selectGgPzRedisPageList(new PageQuery(), ggPzRedis);
    	if(pageResult.getRecords()!=null&&!pageResult.getRecords().isEmpty()) {
    		GgPzRedis detail = pageResult.getRecords().get(0);
    		return ResponseData.successData(detail);
    	}else {
    		return ResponseData.errorMsg("未查询到详细信息！");
    	}
    }
	
    @ServiceLog(businessType = "修改redis配置", systemType = SysConstant.SYSTEM_TYPE, recordResult = true, userId = "")
    @RequiresPermissions("system:redisconfig:edit")
    @PostMapping("/edit")
    @ApiOperation(value = "修改redis配置", notes = "")
    public ResponseData<Integer> edit(@RequestBody GgPzRedis ggPzRedis) {
    	return ResponseData.successData(this.ggPzRedisService.updateGgPzRedis(ggPzRedis));
    }
    
    @ServiceLog(businessType = "测试redis配置", systemType = SysConstant.SYSTEM_TYPE, recordResult = true, userId = "")
    @RequiresPermissions("system:redisconfig:list")
    @PostMapping("/test")
    @ApiOperation(value = "删除redis配置", notes = "")
    public ResponseData<String> remove(@RequestBody List<String> redisIds) {
    	if(redisIds==null||redisIds.size()==0) {
    		return ResponseData.errorMsg("请传入需要测试的redis唯一标志！");
    	}else {
    		return this.ggPzRedisService.testGgPzRedisByRedisIds(redisIds);
    	}
    }
}
